#include <iostream>
using namespace std;
struct ListNode {
  int val;
  ListNode *next;
  ListNode() : val(0), next(nullptr) {}
  ListNode(int x) : val(x), next(nullptr) {}
  ListNode(int x, ListNode *next) : val(x), next(next) {}
};

class Solution {
public:
  ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) {

    int carry, data, temp;
    temp = l1->val + l2->val;
    data = temp % 10;
    carry = temp / 10;
    ListNode *p, *q;
    p = q = new ListNode(data);
    l1 = l1->next;
    l2 = l2->next;
    // 这里千万不要写成 while((l1 = l1->next) && (l2 = l2->next)) ,
    // 这样会发生逻辑短路的情况
    while (l1 && l2) {
      temp = l1->val + l2->val + carry;
      data = temp % 10;
      carry = temp / 10;
      q->next = new ListNode(data);
      q = q->next;
      l1 = l1->next;
      l2 = l2->next;
    }

    while (l1) {
      temp = l1->val + carry;
      data = temp % 10;
      carry = temp / 10;
      q->next = new ListNode(data);
      q = q->next;
      l1 = l1->next;
    }

    while (l2) {
      temp = l2->val + carry;
      data = temp % 10;
      carry = temp / 10;
      q->next = new ListNode(data);
      q = q->next;
      l2 = l2->next;
    }

    if (carry) {
      q->next = new ListNode(carry);
    }

    return p;
  }
};
int main() {
  ListNode *t = new ListNode(0);
  ListNode *s = new ListNode(0);

  return 0;
}
